package com.feicheng.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.AVip;
import com.feicheng.persistence.entity.Client;
import com.feicheng.persistence.mapper.AVipMapper;
import com.feicheng.persistence.service.IAVipService;
import com.feicheng.persistence.service.IClientService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  会员控制器
 * </p>
 *
 * @author cailongyang
 * @since 2024-08-21
 */

@RestController
@RequestMapping("/hy")
@CrossOrigin
public class AVipController {

    @Autowired
    IAVipService iaVipService;

    // 分页相关，展示第current页，每页size条
    @GetMapping("/page")
    public ResultInfo getVipPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size){
        IPage<AVip> page = new Page<>(current, size);
        QueryWrapper<AVip> qw = new QueryWrapper<>();
        return ResultInfo.success(iaVipService.page(page,qw));
    }

    // 动态查询，根据会员编号、所属门店、客户id、客户姓名进行动态查询(多表)
    @GetMapping("/list")
    public ResultInfo getDynamicVip(String dy){
        return ResultInfo.success(iaVipService.selectDynamic(dy));
    }

    // 根据vipid，更新会员信息
    @GetMapping("/update")
    public ResultInfo updateVip(
            @RequestBody AVip vip,
            String vipid){
        QueryWrapper<AVip> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("vipid", vipid);
        AVip originalVip = iaVipService.getOne(queryWrapper);
        originalVip.setSt(vip.getSt());
        originalVip.setEt(vip.getEt());
        originalVip.setZsc(vip.getZsc());
        originalVip.setSysc(vip.getSysc());
        boolean updateResult = iaVipService.updateById(originalVip);
        if (updateResult) {
            return ResultInfo.success("会员信息更新成功");
        } else {
            return ResultInfo.fail("会员信息更新失败");
        }
    }
}
